import React, { Component } from 'react'

//high Component
export default (WrappedComponent,name) =>{
   
    class LocalStorageActions extends  Component{
        constructor(){
            super()
            this.state={
                data:[]
            }
        }

        componentWillMount(){
           let data= localStorage.getItem(name)
           if(data){
               this.setState({
                   date:JSON.parse(data)
               })
           }
        }

        saveData(data){
            localStorage.setItem(name, JSON.stringify(data))
        }

        render(){
            return(
                <WrappedComponent data={this.state.data} saveData={this.saveData.bind(this)} {...this.props}></WrappedComponent>
            )
        }
    }
    return LocalStorageActions
}